package com.spzx.user.service.impl;

import com.spzx.user.service.SmsService;
import com.spzx.user.utils.SMSUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class SmsServiceImpl implements SmsService {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void sedCode(String phone) {
        //生成验证码
        String code = RandomStringUtils.randomNumeric(4);
        //使用SMSUtils工具类向手机发送验证码
        System.out.println("code = " + code);
        //将验证码保存到Redis中,并设置有效时间5分钟
        stringRedisTemplate.opsForValue().set("h5:"+phone,code, 5,TimeUnit.MINUTES);

    }
}
